//
//  YWShowPostTroubleInfoTableViewController.m
//  maintain
//
//  Created by 烟雨云渊 on 16/8/17.
//  Copyright © 2016年 ewin. All rights reserved.
//

#import "YWShowPostTroubleInfoTableViewController.h"
#import "UITableView+FDTemplateLayoutCell.h"
#import "UIColor+CustomColors.h"
#import "YWMacro.h"
#import "YWCommonTool.h"

#import "YWPostTroubleBillCell.h"
#import "YWNewCirculationButtonCell.h"

//#import "YWMission.h"
#import "YWReportTroubleModel.h"

@interface YWShowPostTroubleInfoTableViewController ()<YWNewCirculationButtonCellDelegate>
@end

@implementation YWShowPostTroubleInfoTableViewController

- (instancetype)init{
    return [self initWithStyle:UITableViewStyleGrouped];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"故障详情";
    self.tableView.backgroundColor = [UIColor customBackgroudColor];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerClass:[YWPostTroubleBillCell class] forCellReuseIdentifier:YWPostTroubleBillCellIdentifier];
    [self.tableView registerClass:[YWNewCirculationButtonCell class] forCellReuseIdentifier:YWNewCirculationButtonCellIdentifier];
    self.tableView.estimatedRowHeight = 44.0f;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
}

- (void)setReportTrouble:(YWReportTroubleModel *)reportTrouble{
    _reportTrouble = reportTrouble;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

//- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
//{
//    if (indexPath.section == 0) {
//            return [tableView fd_heightForCellWithIdentifier:YWPostTroubleBillCellIdentifier cacheByIndexPath:indexPath configuration:^(YWPostTroubleBillCell *cell) {
//                cell.fd_enforceFrameLayout = NO;
//                cell.reportTrouble = self.reportTrouble;
//            }];
//    }else{
//        return 60;
//    }
//}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        YWPostTroubleBillCell * cell = [tableView dequeueReusableCellWithIdentifier:YWPostTroubleBillCellIdentifier];
        cell.reportTrouble = self.reportTrouble;
        return cell;
    }else{
        YWNewCirculationButtonCell * cell = [tableView dequeueReusableCellWithIdentifier:YWNewCirculationButtonCellIdentifier];
        cell.delegate = self;
        cell.buttonTitle = @"撤销报障";
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}

- (void)clickCirculationButtonEventWithTitle:(NSString *)buttonTitle{
    if ([self.delegate respondsToSelector:@selector(clickCancelTheReportTrouble:)]) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否取消该报障" preferredStyle:UIAlertControllerStyleAlert];
        [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil]];
        [alert addAction:[UIAlertAction actionWithTitle:@"是" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self.delegate clickCancelTheReportTrouble:self.reportTrouble];
            [self.navigationController popViewControllerAnimated:YES];
        }]];
        [self presentViewController:alert animated:YES completion:nil];
    }else{
        [YWCommonTool showTextHUDWithContent:@"撤销失败,请返回后重试"];
    }
}

@end
